import request from '/@/utils/request'
import type { PreviewInfo } from '../views/oss/file/types'

// 获取文件列表
export function getFileList(params: {
  prefix?: string
  marker?: string
  maxKeys?: number
}) {
  return request({
    url: '/admin/oss/getList',
    method: 'get',
    params
  })
}

// 上传文件
export function uploadFile(data: FormData) {
  return request({
    url: '/admin/oss/upload',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 删除文件
export function deleteFile(path: string) {
  return request({
    url: '/admin/oss/delete',
    method: 'post',
    params: { path }
  })
}

// 创建文件夹
export function createFolder(data: { path: string; name: string }) {
  return request({
    url: '/admin/oss/createFolder',
    method: 'post',
    data
  })
}

// 删除文件夹
export function deleteDirectory(path: string) {
  return request({
    url: '/admin/oss/deleteDir',
    method: 'post',
    params: { path }
  })
}

// 获取文件夹信息
export function getFolderInfo(path: string) {
  return request({
    url: '/admin/oss/getFolderInfo',
    method: 'get',
    params: { path }
  })
}

// 获取文件详情
export function getFileInfo(path: string) {
  return request({
    url: '/admin/oss/getFileInfo',
    method: 'get',
    params: { path }
  })
}

// 获取文件预览URL
export function getPreviewUrl(path: string) {
  return request<PreviewInfo>({
    url: '/admin/oss/getPreviewUrl',
    method: 'get',
    params: { path }
  })
}

// 下载响应类型
export interface DownloadInfo {
  url: string
  file_name: string
  file_size: string
  expire_time: number
}

// 获取下载链接
export function getDownloadUrl(path: string) {
  return request<DownloadInfo>({
    url: '/admin/oss/getDownloadUrl',
    method: 'get',
    params: { path }
  })
} 